package com.study.multithreading;

import java.util.Vector;

/**
 * 创建人： HBZ，时间： 2017/5/22 11:14.
 * 说明：线程安全
 */
public class VectorTest {
    public static void main(String[] args) throws InterruptedException {
        for(int i=0;i<10000;i++){
            Vector<String> vector=new Vector<String>();
            Thread a = new Thread(new AddThread1(vector,"a"));
            Thread b = new Thread(new AddThread1(vector,"b"));
            Thread c = new Thread(new AddThread1(vector,"c"));
            Thread d = new Thread(new AddThread1(vector,"d"));
            Thread e = new Thread(new AddThread1(vector,"e"));
            Thread f = new Thread(new AddThread1(vector,"f"));
            a.start();
            b.start();
            c.start();
            d.start();
            e.start();
            f.start();
            a.join();
            b.join();
            c.join();
            d.join();
            e.join();
            f.join();
            System.out.println(vector.size()+"---"+vector);
        }

    }
    static class AddThread1 implements Runnable {
        Vector<String> list;
        String string;
        public AddThread1(Vector<String> list, String string) {
            this.list = list;
            this.string=string;
        }

        public void run() {
            list.add(string);

        }
    }
}
